package weeny.pre.expression;

import prefuse.data.Schema;
import prefuse.data.Tuple;
import prefuse.data.expression.ColumnExpression;
import prefuse.data.expression.FunctionExpression;
import prefuse.data.expression.Predicate;

/**
 * Test if the field in the tuple is null or not
 * 
 * @author weeny
 *
 */
public class NullPredicate extends FunctionExpression implements Predicate{
	
	public NullPredicate(String column){
		super(1);
		ColumnExpression ce = new ColumnExpression(column);
		addParameter(ce);
	}
	public NullPredicate() {
		super(1);
	}

	@Override
	public String getName() {
		return "NIL";
	}
	public Class getType(Schema s) {
		return boolean.class;
	}
	@Override
	public boolean getBoolean(Tuple t) {
		if ( paramCount() == 1 ) {
			return param(0).get(t) == null;
		}
		missingParams();
		return true;
	}
	@Override
	public Object get(Tuple t) {
		return getBoolean(t);
	}
}
